package com.xieke.admin.schedule;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.xieke.admin.entity.User;
import com.xieke.admin.service.IUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @创建人: zhangjingjing
 * @创建时间 2019/4/17 16:07
 * @当前项目 common-admin
 * @描述: 用于定期刷新cms中相关信息到redis缓存
 */
@Component
public class CmsCacheSchedule {

    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private RedisTemplate redisTemplate;
    @Resource
    private IUserService iUserService;

    @Async("taskExecutor")
    @Scheduled(cron = "0 */2 * * * ?")
    public void testSchedule(){
        int count = iUserService.selectCount(new EntityWrapper<User>());
        logger.info("当前调度统计用户数量:"+count);
        redisTemplate.opsForValue().set("zjj-test-redis","张晶晶测试ddd", 3, TimeUnit.MINUTES);

        String cache = (String) redisTemplate.opsForValue().get("zjj-test-redis");
        logger.info("当前获取缓存数据:"+cache);
    }

}
